Prev Next |
There are two major levels of caching in Sitecore:
- Database caches which are created for each database separately. They are data, path and credential caches.
- Site caches which are created for each site separately. They are html, xsl, registry and viewstate caches.
Cache sizes can be set up either on a specific site or database definition or it can be specified in the <cacheSizes> section. The values set directly on a site or a database will always take precedence over the values set in <cacheSizes>.
Each set of caches is completely unrelated to other sets and works in its own environment with its own data.
Site-level caches are rather specific and work only in certain situations:
- HTML caching works only with output of Sitecore.Web.UI.WebControl class (and its derivatives).
- XSL, registry and viewstate caches work for respective parts of functionality only.
- HTML cache is disabled in the preview, webedit and debug modes.
- XSL cache is cleared when a corresponding XSL is changed in the file system.
The <cacheSizes> section should pretty much be self-explanatory. An example is shown below.
<cacheSizes> section settings
<cacheSizes>
<databases>
<master>
<data>20MB</data> <!-- data cache size for the database -->
<credential>2MB</credential> <!-- security data cache size for the database -->
<path>1MB</path> <!-- file path cache used by items of the database -->
</master>
</databases>
<sites>
<shell>
<html>2MB</html> <!-- html cache size for the site -->
<registry>3MB</registry> <!-- registry cache size for the site -->
<viewState>200KB</viewState> <!-- view state cache size for the site -->
<xsl>5MB</xsl> <!-- xsl renderings cache size for the site -->
</shell>
</sites>
</cacheSizes>
The valid cache names for the <databases> element are:
- data
- credential
- pathMapping
The valid cache names for the <sites> element are:
- html
- registry
- viewstate
- xsl
To set a cache size directly on a database, you must use the properties on the database object (as the database object is constructed by Sitecore.Factory using only reflection).
To set the size of the data cache on the "master" database you can use:
<database id="master" ...>
...
<caches.DataCache.MaxSize>1000000</caches.DataCache.MaxSize>
</database>
Note that the size must be specified in bytes (as the type of the MaxSize property is long).
Database caches are controlled by the CacheOptions.DisableAll setting in the <dataProviders> section of the web.config file. CacheOptions.DisableAll set to true on a dataprovider will disable database-level caches for all databases that use this dataprovider. For instance:
<filesystem type="Sitecore.Data.DataProviders.FileSystemDataProvider, Sitecore.Kernel">
<CacheOptions.DisableAll>true</CacheOptions.DisableAll>
</filesystem>
Below is the list of all web.config cache settings.
Cache size of the IDTable
<IDTable type="Sitecore.Data.$(database).$(database)IDTable, Sitecore.$(database)">
<param desc="cacheSize">500KB</param>
</IDTable>
<site> cache settings
To set a cache size directly on a site, use an attribute named xxxCache where xxx is the name of the cache. For instance, to set the size of the html cache on the web site use:
<site name="website" ... htmlCache="10MB" />
The size can be specified in bytes (no postfix), kilobytes (KB) or megabytes (MB). Spaces and dots are allowed in the value string, so the following is also valid:
<site name="website" ... htmlCache="1.024 KB" />
The settings listed below define the basic cache settings. They are overridden by the settings defined in the <sites> section.
- <setting name="Caching.CacheViewState" value="true" />
<!-- indicates whether to use caching for the view state -->
- <setting name="Caching.DefaultCredentialCacheSize" value="1MB" />
<!-- Determines the default credential cache size (can be redefined for the site) -->
- <setting name="Caching.DefaultDataCacheSize" value="10MB" />
<!-- Determines the default data cache size (can be redefined for the site) -->
- <setting name="Caching.DefaultHtmlCacheSize" value="5MB" />
<!-- Determines the default html cache size (can be redefined for the site) -->
- <setting name="Caching.DefaultPathCacheSize" value="100KB" />
<!-- Determines the default path cache size (can be redefined for the site) -->
- <setting name="Caching.DefaultRegistryCacheSize" value="5MB" />
<!-- Determines the default registry cache size (can be redefined for the site) -->
- <setting name="Caching.DefaultViewStateCacheSize" value="5MB" />
<!-- Determines the default view state cache size (can be redefined for the site) -->
- <setting name="Caching.DefaultXslCacheSize" value="10MB" />
<!-- Determines the default xsl rendering cache size (can be redefine for the site) -->
- <setting name="Caching.Enabled" value="true" />
<!-- Determines if caching should be enabled at all -->
- <setting name="DisableBrowserCaching" value="true" />
<!-- If true, all pages will have: Cache-Control: no-cache, no-store, Pragma: no-cache in the http header -->
1. Cache Duration
If the default cache duration is not sufficient, renderings can be written to perform their own caching.
2. Publishing
Items which are updated by the publishing process are automatically removed from the item XML cache. By default /web.config is configured such that publishing clears the security and rendering caches. In this configuration frequent publication can decrease performance. It is also possible to clear the rendering cache on a scheduled basis.
Prev Next